<?php

namespace app\common\model;

use ShidianUtil\Thinkphp\Model\Traits\BelongsToManyTrait;
use ShidianUtil\Thinkphp\Model\Traits\HasOneThroughTrait;
use ShidianUtil\Thinkphp\Model\Traits\MorphToManyTrait;
use ShidianUtil\Thinkphp\Model\Traits\ScopeTrait;
use ShidianUtil\Utils\NullClearUtil;
use think\db\Query;
use think\Model;

/**
 * 模型基础类
 * Class BaseModel
 * @mixin Query
 * @method null|static find($data = null) 查询模型
 * @package app\common\model
 */
abstract class BaseModel extends Model
{
    use ScopeTrait;
    use HasOneThroughTrait;
    use BelongsToManyTrait;
    use MorphToManyTrait;

    protected $pk = 'id';
    protected $autoWriteTimestamp = true;
    protected $createTime = 'created';
    protected $updateTime = 'updated';
    protected $readonly = ['created'];

    // JsonSerializable
    public function jsonSerialize()
    {
        $array = $this->toArray();
        if (empty($array)) {
            $array = NullClearUtil::getEmptyObject();
        }
        return $array;
    }

    public function getTodoAttr()
    {
        return 'TODO';
    }

}
